﻿using System.Reflection;
using System.Web.Mvc;
using Autofac;

//using NHibernate;

using Autofac.Integration.WebApi;
using System.Web.Http;



namespace Water.RestService
{
    public static class Bootstrapper
    {
        public static void Run()
        {
            SetAutofacContainer();
        }

        private static void SetAutofacContainer()
        {
            //log4net.Config.XmlConfigurator.Configure();

            var builder = new ContainerBuilder();

            //builder.Register(c => ConnectionHelper.BuildSessionFactory()).As<ISessionFactory>().SingleInstance();
            //builder.Register(c => c.Resolve<ISessionFactory>().OpenSession()).InstancePerLifetimeScope();

            //builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            //builder.RegisterModule(new LogInjectionModule());

            //builder.RegisterType<NhUnitOfWork>().As<IUnitOfWork>().InstancePerApiRequest();

            //builder.RegisterAssemblyTypes(typeof(MeterReadingRepository).Assembly).Where(t => t.Name.EndsWith("Repository")).InstancePerLifetimeScope();
            
            IContainer container = builder.Build();

            var resolver = new AutofacWebApiDependencyResolver(container);

            GlobalConfiguration.Configuration.DependencyResolver = resolver;


           
        }
    }
}